//
//  HomeSpatialAudioTableViewCell.swift
//  EasePods
//
//  Created by 易先生 on 2024/4/8.
//

import UIKit

class HomeSpatialAudioTableViewCell: TableViewCell {

    override func makeUI() {
        super.makeUI()
        self.backgroundColor = .clear
        self.contentView.backgroundColor = .clear
        
        self.contentView.addSubview(cardView)
        cardView.addSubview(iconImageView)
        cardView.addSubview(titleLabel)
        cardView.addSubview(descLabel)
        cardView.addSubview(userButton)
        
        cardView.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.leading.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-12)
        }
        
        iconImageView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(18)
            make.leading.equalToSuperview().offset(12)
            make.bottom.equalToSuperview().offset(-18)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(iconImageView.snp.top).offset(2)
            make.leading.equalTo(iconImageView.snp.trailing).offset(10)
        }
        
        descLabel.snp.makeConstraints { make in
            make.leading.equalTo(titleLabel.snp.leading)
            make.bottom.equalTo(iconImageView)
        }
        
        userButton.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-14)
            make.centerY.equalToSuperview()
            make.height.equalTo(32)
        }

    }
    
    func bind(viewModel: HomeSpatialAudioCellModel) {
        iconImageView.image = viewModel.type.iconImage
        titleLabel.text = viewModel.type.title
        descLabel.text = viewModel.type.desc
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    private lazy var cardView: View = {
        let view = View()
        view.backgroundColor = R.color.sound_effect_2_bg()
        view.layer.cornerRadius = 6
        view.layer.masksToBounds = true
        return view
    }()
    
    private lazy var iconImageView: ImageView = {
        let imageView = ImageView()
        imageView.image = R.image.ic_home_tips()
        return imageView
    }()
    
    private lazy var titleLabel: Label = {
        let lable = Label()
        lable.font = Fonts.mediumSystemFont(ofSize: 14)
        lable.textColor = R.color.sound_effect_3_text()
        return lable
    }()
    
    private lazy var descLabel: Label = {
        let lable = Label()
        lable.font = Fonts.systemFont(ofSize: 12)
        lable.textColor = R.color.sound_effect_4_text()
        return lable
    }()
    
    private lazy var userButton: UIButton = {
        let button = UIButton()
        button.setTitle(R.string.localizable.common_use_button_title(), for: .normal)
//        button.setTitleColor(R.color.sound_effect_6_unchoosed(), for: .normal)
        button.titleLabel?.font = Fonts.mediumSystemFont(ofSize: 12)
        button.contentEdgeInsets = UIEdgeInsets(top: 5, left: 16, bottom: 5, right: 16)
        button.titleLabel?.numberOfLines = 0
        button.layer.borderWidth = 0.5
//        button.layer.borderColor = R.color.sound_effect_6_unchoosed()?.cgColor
        button.backgroundColor = .clear
        button.layer.cornerRadius = 16
        return button
    }()
}


extension HomeSpatialAudioItem {
    var title: String {
        switch self {
        case .music:
            return R.string.localizable.home_spatial_audio_music_title()
        case .movie:
            return R.string.localizable.home_spatial_audio_movie_title()
        case .game:
            return R.string.localizable.home_spatial_audio_game_title()
        }
    }
    
    var desc: String {
        switch self {
        case .music:
            return R.string.localizable.home_spatial_audio_music_desc()
        case .movie:
            return R.string.localizable.home_spatial_audio_movie_desc()
        case .game:
            return R.string.localizable.home_spatial_audio_game_desc()
        }
    }
    
    
    var iconImage: UIImage? {
        switch self {
        case .music:
            return R.image.ic_sound_effect_1()
        case .movie:
            return R.image.ic_sound_effect_2()
        case .game:
            return R.image.ic_sound_effectl_3()
        }
    }
}
